#include "Anx_RTT.h"

#include "FreeRTOS.h"
#include "task.h"

char TxBuf[384];
char buffer[256];

void Anx_RTT(char level, const char* tag, const char* format, ...)
{
    // taskENTER_CRITICAL();

    va_list args;
    va_start(args, format);
    vsnprintf(buffer, sizeof(buffer), format, args);
    va_end(args);

    sprintf(TxBuf, "[%s] %s\r\n", tag, buffer);
    int len = strlen(TxBuf);
    TxBuf[len] = '\0'; // 强制结尾

    SEGGER_RTT_WriteNoLock(0, TxBuf, len);

    // taskEXIT_CRITICAL();
}


void Anx_RTT_ISR(const char* data)
{
    UBaseType_t uxSavedStatus;
    uxSavedStatus = portSET_INTERRUPT_MASK_FROM_ISR();

    SEGGER_RTT_WriteNoLock(0, data, strlen(data));

    portCLEAR_INTERRUPT_MASK_FROM_ISR(uxSavedStatus);
}

